package com.lhy.wcss.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lhy.wcss.model.dto.DeleteDTO;
import com.lhy.wcss.model.dto.PageDTO;
import com.lhy.wcss.model.vo.BatchSettingVO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.lhy.wcss.common.JsonResponse;
import com.lhy.wcss.service.BatchSettingService;
import com.lhy.wcss.model.domain.BatchSetting;

import java.util.List;


@Controller
@RequestMapping("/batchSetting")
public class BatchSettingController {

    private final Logger logger = LoggerFactory.getLogger( BatchSettingController.class );

    @Autowired
    private BatchSettingService batchSettingService;

    @PostMapping("/save")
    @ResponseBody
    public JsonResponse save(@RequestBody BatchSetting batchSetting){
        boolean save = batchSettingService.save(batchSetting);
        return JsonResponse.success(save);

    }

    @GetMapping("/change")
    public String change(){
        return "redirect:/batch-list";
    }

    @GetMapping("/batchList")
    @ResponseBody
    public JsonResponse getPage(PageDTO pageDTO,BatchSetting batchSetting){
        Page<BatchSettingVO> page =batchSettingService.getPage(pageDTO,batchSetting);
        return JsonResponse.success(page);

    }

    @GetMapping("list")
    @ResponseBody
    public JsonResponse batchsetting(PageDTO pageDTO,BatchSetting batchSetting){
        Page<BatchSetting> page= batchSettingService.pageList(pageDTO,batchSetting);
        return JsonResponse.success(page);
    }

    @PostMapping("removeList")
    @ResponseBody
    public JsonResponse removeList(@RequestBody DeleteDTO deleteDTO){
        boolean b = batchSettingService.removeByIds(deleteDTO.getIdList());
        return JsonResponse.success(b);
    }

    @GetMapping("removeById")
    @ResponseBody
    public JsonResponse removeById(Long id){
        boolean b = batchSettingService.removeById(id);
        return JsonResponse.success(b);
    }

    @PostMapping("insert")
    @ResponseBody
    public JsonResponse insert(BatchSetting batchSetting){
        return JsonResponse.success(batchSettingService.save(batchSetting));
    }

    @PostMapping("reset")
    @ResponseBody
    public JsonResponse reset(BatchSetting batchSetting){
        boolean b = batchSettingService.reset(batchSetting);
        return JsonResponse.success(b);
    }
}

